package com.yxym.thread_;

public class Thread03 {
    public static void main(String[] args) {
//        Fish fish = new Fish();
//        fish.start();
//        //System.out.println("主线程.." + Thread.currentThread().getName());
//        for(int i = 0; i < 10; i++){
//            System.out.println("主线程i=" + i);
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }

        //对使用Runnable接口的方法进行测试...
        T1 t1 = new T1();
        Thread thread = new Thread(t1);
        thread.start();
    }
}

//使用Thread
//@SuppressWarnings({"all"})
//class Fish extends Thread{
//    int count = 0;
//    @Override
//    public void run() {
//        while (true){
//            System.out.println("hello world!" + (count++));
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            if(count == 10){
//                break;
//            }
//        }
//    }
//}

//使用Runnable
@SuppressWarnings({"all"})
class T1 implements Runnable{
    int count2 = 0;
    @Override
    public void run() {
        while (true) {
            System.out.println("hi" + (count2++));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (count2 == 50){
                break;
            }
        }
    }
}
